package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.ProductSkuVo;
import com.spzx.product.api.domain.SkuPriceVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteProductFallbackFactory.class);

    @Override
    public RemoteProductService create(Throwable throwable) {
        log.error("商品服务调用失败:{}", throwable.getMessage());
        return new RemoteProductService()
        {
            @Override
            public R<ProductSkuVo> getProductSku(Long skuId, String source) {
                return R.fail("获取商品sku失败:" + throwable.getMessage());
            }

            @Override
            public R<ProductSkuVo> getSkuPrice(Long skuId, String source) {
                return R.fail("获取商品sku价格失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SkuPriceVo>> getSkuPriceList(List<Long> skuIdList, String source) {
                return R.fail("获取商品sku价格列表失败:" + throwable.getMessage());
            }
        };
    }
}